package org.hnxxxy.ebms.util;

import com.auth0.jwt.JWT;
import org.apache.shiro.SecurityUtils;
import org.bouncycastle.crypto.generators.BCrypt;
import org.hnxxxy.ebms.common.constant.Constant;
import org.springframework.stereotype.Component;

import java.util.regex.Pattern;

/**
 * @Description:
 * @Author WANGWEI
 * @Date: 2021/1/20  22:36
 * @EMAIL: 1377366738@qq.com
 */
@Component
public class CommonUntil {

    /**
     * @Description: 加密
     * @Author WANGWEI
     * @Date: 2021/1/20  22:36
     * @EMAIL: 1377366738@qq.com
     **/
    public static String bCrypt(String password,String salt){
        return new String(BCrypt.generate(password.getBytes(), salt.getBytes(),4));
    }

    public static void main(String[] args) {
        System.out.println(bCrypt("admin", "1234567891234567"));
    }


    /**
     * @Description: 判断是否是邮箱
     * @Author WANGWEI
     * @Date: 2021/1/20  22:38
     * @EMAIL: 1377366738@qq.com
     **/
    public static boolean isMail(String mail){
        return Pattern.matches("[^@ \\t\\r\\n]+@[^@ \\t\\r\\n]+\\.[^@ \\t\\r\\n]+",mail);
    }

    /**
     * 获取当前用户id
     */
    public static Integer getId(){
        String principal = String.valueOf(SecurityUtils.getSubject().getPrincipal());
        return JWTUtil.getId(principal);
    }
}
